package com.xjzd.std.lambda;

import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.BiConsumer;
import java.util.function.IntPredicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public class LambdaTest {

    public static void main(String[] args) {
        IntPredicate predicate = x -> x > 5;
        System.out.println(predicate.test(10));
        System.out.println(predicate.test(1));

        System.out.println(predicate.and(x -> x < 10).test(8));

        BiConsumer<StringJoiner, Integer> consumer = (joiner, t) -> joiner.add(String.valueOf(t));
        System.out.println(Stream.of(1, 2, 3, 4)
                .collect(
                        () -> new StringJoiner("->"),
                        consumer,
                        (joiner, t) -> joiner.add(String.valueOf(t))
                ));

        IntStream.iterate(Integer.MAX_VALUE, a -> a + 1).limit(1000).forEach(System.out::println);

        IntStream.generate(() -> ThreadLocalRandom.current().nextInt(10)).limit(5).forEach(System.out::println);

        ThreadLocalRandom.current().ints(10).forEach(System.out::println);

        IntStream.of(1, 2, 31, 23, 1, 31, 3, 1)
                .distinct().forEach(System.out::println);

        Stream.of(-1, 2, 3)
                .collect(ArrayList::new, List::add, (a, b) -> {
                })
                .forEach(System.out::println);

        // Stream.of(-1, 2, 3).collect(Collectors.groupingBy())
    }
}

@FunctionalInterface
interface IntTernaryOperator {

    int op(int a, int b, int c);
}